
import { _decorator, Component, Node, Tween, CCInteger, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Attack
 * DateTime = Sat Feb 05 2022 15:07:57 GMT+0800 (China Standard Time)
 * Author = vvc_zeng
 * FileBasename = Attack.ts
 * FileBasenameNoExtension = Attack
 * URL = db://assets/script/animation/Attack.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */

@ccclass('Attack')
export class Attack extends Component {
    // 备份位置信息
    pos = null;
    onLoad() {
        this.pos = this.node.getPosition();
    }
    start() {
    }
    onEnable() {
    }
    onDisable() {
        // 位置恢复
        this.node.setPosition(this.pos);
    }
    onDestroy() {
    }
    // 如果有 callback ，就在动画结束时调用
    play(destPos, callback?) {
        this.node.active = true;
        new Tween(this.node)
            .to(0.8, { position: destPos }, { easing: 'linear' })
            .call(() => {
                this.node.active = false;
                if (typeof callback == 'function') {
                    callback()
                }
            })
            .start()
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */
